package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.DatiInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by windo on 16/7/13.
 */
public class DatiDetailTask extends CouponHttpBaseTask {
    private String questionId;

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject jsonObject = response.getBody();
        DatiInfo info = null;
        if (jsonObject != null) {
            info = JSON.parseObject(jsonObject.getString("data"), DatiInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, info);
    }

    public DatiDetailTask(String id) {
        super();
        questionId = id;
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.DATI_DETAIL);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("questionId", questionId);
            request.setData(jsonObject.toString());
            addRequest(request);
        }
    }
}
